package Yang.homework;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class StringWriteTest {
    public static void main(String[] args) {
        System.out.println("请输入相关内容");
        Scanner sc = new Scanner(System.in);
        List<String> all = new ArrayList<>();
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter("d:/a.txt"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        while(true){
            String str = sc.next();
            if ("end".equals(str)){
                break;
            }else{
                all.add(str);
            }
        }
        Collections.sort(all);
        System.out.println(all);
        for (int i = 0; i<all.size();i++){
            try {
                bw.write(all.get(i) + "\n");
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (null != bw){
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
